<?php
/**
 * @智库类
 * 1、智库列表
 * 2、智库详情
 *
*/
namespace app\tank\controller;
use app\common\controller\HomeCommon;
use think\Cache;
use think\Config;

class Index extends HomeCommon
{
	public function __construct(){
		
		parent::__construct();
		
		
	}
	
	
	/**
	 * 获得智库列表
	*/
	public function get_tank(){
		
		
		$where="  a.status=1  ";
	
		$field="a.identification,a.member_name,a.headimgurl,a.desc";
		$obj=db('tank_member a');
	
		
		
//		$act=request()->param('act','','trim');
//		dd($act);
        $act='member';
/***关键字**/
		$keywords=request()->param('keywords','','trim');
		if(!empty($keywords)){
			$where.=" and a.".$act."_name like '%$keywords%' ";
		}
/***行业**/
		$industry_id=request()->param('industry_id',0,'intval');
		if(!empty($industry_id)){
			$obj=$obj->join('tank_'.$act.'_industry b','a.id=b.tank_id');
			$where.=" and b.status=1 and b.industry_id=$industry_id";
		}
		
/***产业链**/
		$chain_id=request()->param('chain_id',0,'intval');
		if(!empty($chain_id)){
			$obj=$obj->join('tank_'.$act.'_chain c','a.id=c.tank_id');
			$where.=" and c.status=1 and c.chain_id=$chain_id";
		}
		
/***城市**/
		$city_id=request()->param('city_id',0,'intval');
		if(!empty($city_id)){
			$where.=" and (a.province_id=$city_id or a.city_id=$city_id or a.area_id=$city_id ) ";
		}

      // 设置分页数据
        $page=request()->param('page',0,'intval');
        $limit=request()->param('limit',15,'intval');
        Config::set('paginate.page',bcadd($page,1));
		$listobj=$obj->field($field)->where($where)->order('a.id desc')->paginate()->toArray($limit);
		
		
		
		
		
		
		return json(['errcode'=>'0','msg'=>lang('Get success'),'data'=>$listobj]);
		
		
	}
	
	/**
	 * 获得机构详情
	*/
	public function get_tank_info(){
		
		
		$where['status']=['=',1];
		
		
		$identification=request()->param('identification','','trim');
		
		$field="a.id,a.identification,a.member_name,a.headimgurl,a.desc,a.join_time,a.education,a.career,a.work";
			
		$act='member';
		
		if(!empty($identification)){
			$where['identification']=['=', $identification];
			
			
			$cache=new Cache();
			
			$result=$cache->get('tank_'.$act.'_'.$identification);
			
			
			if($result){
				$info=unserialize($result);
			}else{
				$model= model('Commondata');
				
				$info=$model->get_detail('tank_'.$act.' a',$field,$where);
				
				$info['education']=education($info['education']);
				
		//查看学历
				$education=db('tank_member_education')
				->field('start_time,end_time,school,education,professional')
				->where(['tank_id'=>$info['id'],'status'=>1])
				->order('id desc')
				->select();
				foreach ($education as &$val){
					$val['education']=education($val['education']);
				}
				$info['edu_experience']=$education;
				
		//查看经历
				$experience=db('tank_member_experience a')
				->join('companys b',"a.com_id=b.id",'left')
				->field('a.start_time,a.end_time,a.career,a.work,b.company_name,b.identification as com_identification')
				->where(['tank_id'=>$info['id'],'a.status'=>1])
				->order('a.id desc')
				->select();
				
				$info['experience']=$experience;
				
				
				unset($info['id']);
				$cache->set('tank_'.$act.'_'.$identification, serialize($info),3600);
			}
			
			
			return json(['errcode'=>'0','msg'=>lang('Get success'),'data'=>$info]);
			
			
		}else{
			return json(['errcode'=>'-1','msg'=>lang('param error'),'data'=>[]]);
		}
		
		
		
		
		
	}
}
